<?php
/**
 * Controller is the customized base controller class.
 * All controller classes for this application should extend from this base class.
 */
class Controller extends CController
{
	/**
	 * @var string the default layout for the controller view. Defaults to '//layouts/column1',
	 * meaning using a single column layout. See 'protected/views/layouts/column1.php'.
	 */
	//public $layout='//layouts/column1';
	public $layout='//layouts/layouts_1';
	/**
	 * @var array context menu items. This property will be assigned to {@link CMenu::items}.
	 */
	public $menu=array();
	
	public $userInfo = "";
	/**
	 * @var array the breadcrumbs of the current page. The value of this property will
	 * be assigned to {@link CBreadcrumbs::links}. Please refer to {@link CBreadcrumbs::links}
	 * for more details on how to specify this property.
	 */
	public $breadcrumbs=array();
	
	/**
	 * 用户登录信息
	 * Enter description here ...
	 */
	
	//array('nick'=>'star','phone'=>'15889744181','email'=>'star@139talk.com');
	
	
	/**
	 * (non-PHPdoc)
	 * @see yii/framework/web/CController::init()
	 */
	public function init(){
		
		/*$data = $_GET;
		print_r($data);exit;
		foreach($data as $k=>$v){
			$exp = explode('/', $k);
			$_GET[$exp[0]] = $exp[1];
		}*/
		$this->login();
	}
	public function login(){
		if(!$this->chkUserLogin()){
			$this->redirect($this->createUrl("user/login"));
		}
		$this->userInfo = $_SESSION["userInfo"];
		
	}
	public function chkUserLogin(){
		$name = $_SESSION["userInfo"]["Name"];
			
		
		if(empty($name) && !preg_match("/user\/login|captcha/",$_SERVER["REQUEST_URI"])){
			
			return false;
		}
		return true;
	}
	public function actions()
	{
		return array(
			// captcha action renders the CAPTCHA image displayed on the contact page
			'captcha'=>array(
				'class'=>'CCaptchaAction',
				'backColor'=>0xFFFFFF,
				'maxLength'=>6,       // 最多生成几个字符 
			),
			// page action renders "static" pages stored under 'protected/views/site/pages'
			// They can be accessed via: index.php?r=site/page&view=FileName
			'page'=>array(
				'class'=>'CViewAction',
			),
		);
	}
	/**
	 * 动态加载公共部件
	 * Enter description here ...
	 */
	public function helper(){
		$help = new Helper();
		return $help;
	}
}